package com.ayoka.parenting.adapter;

import android.support.v7.widget.AppCompatTextView;

import com.ayoka.parenting.R;
import com.ayoka.parenting.bean.MeditationQuestionBean;
import com.jincp.common.brvah.BaseQuickAdapter;
import com.jincp.common.brvah.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;


/**
 * @ProjectName: ayoka7.
 * @ClassName: MeditationQuestionOptionAdapter.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/8/6 21:15.
 */

public class MeditationQuestionOptionAdapter extends BaseQuickAdapter<MeditationQuestionBean.OptionsBean, BaseViewHolder> {

    public static int SINGLE_MODE = 0;
    public static int MULTI_MODE = 1;

    private int selectorMode;

    public MeditationQuestionOptionAdapter(int selectorMode) {
        super(R.layout.item_meditation_question_option);
        this.selectorMode = selectorMode;
    }

    @Override
    protected void convert(BaseViewHolder holder, MeditationQuestionBean.OptionsBean item) {
        AppCompatTextView textView = holder.getView(R.id.tv_option);
        textView.setText(item.Option);
        textView.setSelected(item.isSelected);
        if (selectorMode == SINGLE_MODE) {
            textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.selector_radio_button_primary_with_hook, 0, 0,  0);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.selector_check_box_primary_with_hook, 0, 0, 0);
        }
    }

    public void setSingleChoice(int position) {
        for (int i = 0; i < getData().size(); i++) {
            if (getItem(i) == null) continue;
            getItem(i).isSelected = i == position;
        }
        notifyDataSetChanged();
    }

    public void setMultiChoice(int position) {
        getItem(position).isSelected = true;
        notifyItemChanged(position);
    }

    public List getChoiceData() {
        List result = new ArrayList();
        for (MeditationQuestionBean.OptionsBean optionsBean : getData()) {
            if (optionsBean.isSelected) {
                result.add(optionsBean.Index);
            }
        }
        return result;
    }

}
